import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.commons.utils import JsCode
# 堆叠区域图

x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
y_data = [820, 932, 901, 934, 1290, 1330, 1320]
#用JS画出颜色
background_color_js = (
    "new echarts.graphic.LinearGradient(0, 0, 0, 1, "
    "[{offset: 0, color: '#c86589'}, {offset: 1, color: '#06a7ff'}], false)"
)
area_color_js = (
    "new echarts.graphic.LinearGradient(0, 0, 0, 1, "
    "[{offset: 0, color: '#eb64fb'}, {offset: 1, color: '#3fbbff0d'}], false)"
)

Chart = Line(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js)))
Chart.add_xaxis(xaxis_data=x_data)
Chart.add_yaxis(series_name="",
                y_axis=y_data,
                symbol="emptyCircle",
                #显示线上的圆点
                is_symbol_show=True,
                #平滑过渡
                is_smooth=True,
                #显示线上的数值
                label_opts=opts.LabelOpts(is_show=True),
                #此处为堆叠区域，线的16进制色号为"#5A6B8F"，区域为"#8995AF"
                # areastyle_opts=opts.AreaStyleOpts(opacity=1, color="#8995AF"),
                areastyle_opts=opts.AreaStyleOpts(color=JsCode(area_color_js), opacity=1))
#opacity为不透明度，越接近1越不透明
Chart.set_series_opts(areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
                      label_opts=opts.LabelOpts(is_show=False))
Chart.set_global_opts(
    tooltip_opts=opts.TooltipOpts(is_show=True),
    yaxis_opts=opts.AxisOpts(type_="value",
                             #True为隐藏线上的圆点及数值
                             axistick_opts=opts.AxisTickOpts(is_show=True),
                             #True为显示平行于X轴的水平线
                             splitline_opts=opts.SplitLineOpts(is_show=True)),
    #True为X轴的系列名显示在两刻度的中间，False显示在每一刻度之上
    xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False))
# 设置 boundary_gap 的时候一定要放在最后一个配置项里, 不然会被覆盖
Chart.render("basic_area_chart.html")
